package thread;

/**
 * @author Bboy Dday
 * @create 2020:06:14--21:10
 */
public class WindowTest4 {

    public static void main(String[] args) {

        Window4 w1 = new Window4();
        Window4 w2 = new Window4();
        Window4 w3 = new Window4();

        w1.setName("窗口1");
        w2.setName("窗口2");
        w3.setName("窗口3");

        w1.start();
        w2.start();
        w3.start();
    }

}

class Window4 extends Thread{

    private static int ticket = 100;
    private static boolean  flag = true;

    @Override
    public void run(){

        while (flag){
            show();
        }
    }

    public static synchronized void show(){
        if (ticket > 0) {
            try {
                Thread.sleep( 100 );
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " : " + "售票" + " : " + ticket);
            ticket--;
        }else flag = false;
    }

}